package com.example.suze.libraryinformationmanagementsystem.Adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.suze.libraryinformationmanagementsystem.R;
import com.example.suze.libraryinformationmanagementsystem.net.entiry.InfoDatum;
import com.person.entity.Book;
import com.person.entity.Notes;

import java.util.List;

/**
 * Created by suze on 2017/6/12.
 */

public class PersonListAdapter extends BaseAdapter {
    private Context context;

    private List<InfoDatum> list=null;

    public PersonListAdapter(Context context, List<InfoDatum> list) {
        this.context = context;
        this.list = list;
    }

    /**
     * 传入新的数据 刷新UI的方法
     */
    public void updateListView(List<InfoDatum> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        InfoDatum mContent = list.get(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.person_list, null);
            viewHolder.name = (TextView) convertView.findViewById(R.id.person_book_name);
            viewHolder.time = (TextView) convertView.findViewById(R.id.person_book_time);
            viewHolder.status= (TextView) convertView.findViewById(R.id.person_book_status);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.name.setText(mContent.getbook_name());
        viewHolder.time.setText(mContent.getborrow_date()+"——"+mContent.getreturn_date());
        if(mContent.getstatus()){
            viewHolder.status.setText("未归还");
            viewHolder.status.setTextColor(0xffff0000);
        }else {
            viewHolder.status.setText("已归还");
            viewHolder.status.setTextColor(0xff00ff00);
        }

        return convertView;
    }

    class ViewHolder {
        TextView name;
        TextView time;
        TextView status;
    }
}
